package com.internal.Internalhibernate.server.dao;

// Generated Feb 24, 2012 1:32:12 PM by Hibernate Tools 3.3.0.GA

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.internal.Internalhibernate.client.AdmRequestsType;
import com.internal.Internalhibernate.server.SessionFactoryUtil;

/**
 * Home object for domain model class AdmRequestsType.
 * 
 * @see dao.AdmRequestsType
 * @author Hibernate Tools
 */
public class AdmRequestsTypeDAO {

	private static final Log log = LogFactory.getLog(AdmRequestsTypeDAO.class);

	private final SessionFactory sessionFactory = SessionFactoryUtil
			.getSessionFactory();

	public void persist(AdmRequestsType transientInstance) {
		log.debug("persisting AdmRequestsType instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.persist(transientInstance);
			trans.commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(AdmRequestsType instance) {
		log.debug("attaching dirty AdmRequestsType instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.saveOrUpdate(instance);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AdmRequestsType instance) {
		log.debug("attaching clean AdmRequestsType instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.lock(instance, LockMode.NONE);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(AdmRequestsType persistentInstance) {
		log.debug("deleting AdmRequestsType instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.delete(persistentInstance);
			trans.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("delete failed", re);
			throw re;
		}
	}

	public AdmRequestsType merge(AdmRequestsType detachedInstance) {
		log.debug("merging AdmRequestsType instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmRequestsType result = (AdmRequestsType) session
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("merge failed", re);
			throw re;
		}
	}

	public AdmRequestsType findById(byte id) {
		log.debug("getting AdmRequestsType instance with id: " + id);
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmRequestsType instance = (AdmRequestsType) session.get(
					"com.internal.Internalhibernate.client.AdmRequestsType",
					id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findAll() {
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createQuery("from AdmRequestsType");
		return q.list();
	}

	public String getTypeDsc(byte id) {
		try {
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			Query q = session
					.createQuery("select typeDesc from AdmRequestsType where typeId = '"
							+ id + "'");
			return (String) q.uniqueResult();
		} catch (RuntimeException re) {
			log.error("get Type Desc by id failed :", re);
			throw re;
		}
	}
}
